package com.woniu.sharepark.leasesystem.tenant.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.sharepark.common.JsonResult;
import com.woniu.sharepark.leasesystem.tenant.pojo.Complaint;
import com.woniu.sharepark.leasesystem.tenant.service.ComplaintService;
import com.woniu.sharepark.leasesystem.tenant.vo.ComplaintVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@ClassName ComplaintController
 *@Description 处理前端投诉请求的controller
 *@Author litong
 *@Date 2019/6/5 17:14
 *@Version 1.0
 **/
@Controller
@RequestMapping("/complaint")
public class ComplaintController {

    @Autowired
    private ComplaintService complaintService;
    /**
    *根据被投诉方id分页查询所有投诉信息
    * @title allComplaints
    * @param currentPage
     * @param pageSize
     * @param complaintVO
    * @return java.util.Map
    * @author litong
    * @date 2019/6/5 19:27
    **/
   @RequestMapping("/allComplaint")
   @ResponseBody
    public Map allComplaints(@RequestParam(value = "page" ,defaultValue = "1",required = false) Integer currentPage,
                             @RequestParam(value = "rows",defaultValue = "5",required = false)Integer pageSize,
                             ComplaintVO complaintVO){

       List list=new ArrayList();
       list=complaintService.allComplaints(currentPage,pageSize,complaintVO);
       PageInfo<Complaint>pageInfo=new PageInfo<>(list);
       Map map=new HashMap();
       map.put("rows",pageInfo.getList());
       map.put("total",pageInfo.getTotal());
       return map;
    }
    /**
    * 添加投诉
    * @title
    * @param complaint
    * @return com.woniu.sharepark.common.JsonResult
    * @author litong
    * @date 2019/6/10 9:43
    **/
    @RequestMapping("/addComplaint")
    @ResponseBody
    public JsonResult addComplaint(Complaint complaint,Integer oId){
     return complaintService.addComplaint(complaint,oId);
    }

    /**
    * 投诉租客
    * @title addComplaintToTenant
    * @param complaint
     * @param oId
    * @return com.woniu.sharepark.common.JsonResult
    * @author litong
    * @date 2019/6/21 10:31
    **/
    @RequestMapping("/addComplaintToTenant")
    @ResponseBody
    public JsonResult addComplaintToTenant(Complaint complaint,Integer oId){
        return complaintService.addComplaintToTenant(complaint,oId);
    }
    /**
    * 根据投诉id处理投诉
    * @title disposeComplaint
    * @param coId
    * @return com.woniu.sharepark.common.JsonResult
    * @author litong
    * @date 2019/6/10 9:45
    **/
    @RequestMapping("/disposeComplaint")
    @ResponseBody
    public JsonResult disposeComplaint(Integer coId){
       return complaintService.disposeComplaint(coId);
    }
}
